<script>
    function addEmoticon(target, emo){
    
    elem = document.getElementById(target);
    elem.value += " :" + emo + ":";
}

function quoteMessage(username, post_content){
    elem = document.getElementById('post_text');
    current_content = elem.value;
    elem.value = "[quote="+username+"]"+post_content+"[/quote]";
}

</script>
<div id="content_left">
    <div class="post">

        <div class="post_content">
         
        {if isset($user) && $user->isLogged()}
        {if isset($mode) && $mode eq 'forum'}<p style="vertical-align: middle;"><img style="vertical-align: middle;"src="static/images/layout/addtopic.png" /> <a href="forum.php?mode=forum&id={$forum->id_forum}&action=add">Crea una nuova discussione </a></p>{/if}
        <br /> <br />
        <table class="tab" width="590" border="1">
            <tbody>
                
            <b>Navigazione: </b>
            <a href="forum.php">Indice</a>{if isset($mode) && $mode eq 'forum'} :: <a href="forum.php?mode=forum&id={$forum->id_forum}">{$forum->name}</a>{/if}{if isset($mode) && $mode eq 'topic'} :: <a href="forum.php?mode=forum&id={$forum->id_forum}">{$forum->name}</a> :: <a href="forum.php?mode=topic&id={$topic->id_topic}">{$topic->name}</a>{/if}

            <!-- Sezione per le categorie -->
            {if !isset($mode)}
                {foreach from=$categories item=cat name=cats}
                    <tr>
                        <td class="tb_head" style="padding-left: 15px;" colspan="2">{$cat->name}</td>
                        <td class="tb_head" align="center">Contenuto</td>
                        <td class="tb_head" align="center">Ultimo mess.</td>
                        {if $user->isAdmin()}
                        <td class="tb_head" align="center">Admin</td>
                        <td class="tb_head" align="center" width="25">
                            <a href="forum.php?mode=category&id={$cat->name}&action=remove">
                                <img valign="middle" src="static/images/layout/remove.png" />
                            </a>
                        </td>
                        {/if}
                    </tr>
                    {foreach from=$cat->getForums() item=forum name=forums}
                        <tr class="li">
                            <td class="ic" width="40">
                                <a href="forum.php?mode=forum&id={$forum->id_forum}">
                                    <img border="0" alt="" src="static/images/layout/cartelletta.png">
                                </a>
                            </td>
                            <td class="c1" width="330">
                                <div class="datb">
                                    <a href="forum.php?mode=forum&id={$forum->id_forum}">
                                        <b>{$forum->name}</b>
                                    </a>
                                </div>
                                <div class="dat">
                                    {$forum->desc}
                                </div>
                            </td>
                            <td class="c2" width="100">
                                <div class="dat">
                                    {$forum->getNrTopic()} discussioni
                                    <br>
                                    {$forum->getNrPosts()} mess.
                                </div>
                            </td>
                            <td class="c3" width="120">
                                <div class="dat">
                                    {if $forum->getLastMessageDate() neq false}
                                        {Util::getDate($forum->getLastMessageDate())} alle {Util::getTime($forum->getLastMessageDate())}
                                    {/if}
                                    <br />
                                    {if $forum->getLastMessageCreator() neq "nessuno"}
                                    da 
                                    <a id="m" class="a_profilo" href="profile.php?username={$forum->getLastMessageCreator()}">{$forum->getLastMessageCreator()}</a>
                                    
                                    {else}
                                        Nessun messaggio
                                    {/if}
                                    
                                </div>
                                    
                            </td>
                            {if $user->isAdmin()}
                            <td class="c3" width="40">
                                <a href="forum.php?mode=forum&id={$forum->id_forum}&action=remove">
                                    <img valign="middle" src="static/images/layout/remove.png" />
                                </a>
                            </td>
                            {/if}
                        </tr>
                    {/foreach}
                {/foreach}
            {elseif isset($mode) && $mode eq 'forum'}
                {if isset($action) && $action eq 'add'}
                    <!-- Creazione Topic -->
                    <h3>Crea nuova discussione</h3>
                    {$openTopicForm}
                    <table id="reply_message">
                        <tr>
                            <td>
                                {$add_topic_title}
                            </td>
                        </tr>
                        <tr>
                            <td>
                                {$add_topic_content}
                            </td>
                            
                        </tr>
                        <tr>
                            <td>
                                {$add_topic_submit} 
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <h3>Smiles</h3>

                                <img src="static/images/emo/angry.gif" alt="angry" onclick="addEmoticon('topic_content', 'angry');" /> 
                                <img src="static/images/emo/biggrin.gif" alt="biggrin" onclick="addEmoticon('topic_content', 'biggrin');"  /> 
                                <img src="static/images/emo/blink.gif" alt="blink" onclick="addEmoticon('topic_content', 'blink');"  /> 
                                <img src="static/images/emo/blushing.gif" alt="blushing" onclick="addEmoticon('topic_content', 'blushing');"  /> 
                                <img src="static/images/emo/bored.gif" alt="bored" onclick="addEmoticon('topic_content', 'bored');"  />
                                <img src="static/images/emo/confused.gif" alt="confused" onclick="addEmoticon('topic_content', 'confused');"  /> 
                                <img src="static/images/emo/cool.gif" alt="cool" onclick="addEmoticon('topic_content', 'cool');"  /> 
                                <img src="static/images/emo/crying.gif" alt="crying" onclick="addEmoticon('topic_content', 'crying');"  /> 
                                <img src="static/images/emo/cursing.gif" alt="cursing" onclick="addEmoticon('topic_content', 'cursing');"  /> 
                                <img src="static/images/emo/drool.gif" alt="drool" onclick="addEmoticon('topic_content', 'drool');"  /> 
                                <img src="static/images/emo/flapper.gif" alt="flapper" onclick="addEmoticon('topic_content', 'flapper');"  /> 
                                <img src="static/images/emo/glare.gif" alt="glare" onclick="addEmoticon('topic_content', 'glare');"  /> 
                                <img src="static/images/emo/huh.gif" alt="huh" onclick="addEmoticon('topic_content', 'huh');"  /> 
                                <img src="static/images/emo/laugh.gif" alt="laugh" onclick="addEmoticon('topic_content', 'laugh');"  /> 
                                <img src="static/images/emo/lol.gif" alt="lol" onclick="addEmoticon('topic_content', 'lol');"  /> 
                                <img src="static/images/emo/love.gif" alt="love" onclick="addEmoticon('topic_content', 'love');"  /> 
                                <img src="static/images/emo/mad.gif" alt="mad" onclick="addEmoticon('topic_content', 'mad');"  /> <br />
                                <img src="static/images/emo/mellow.gif" alt="mellow" onclick="addEmoticon('topic_content', 'mellow');"  /> 
                                <img src="static/images/emo/ohmy.gif" alt="ohmy" onclick="addEmoticon('topic_content', 'ohmy');"  /> 
                                <img src="static/images/emo/rolleyes.gif" alt="rolleyes" onclick="addEmoticon('topic_content', 'rolleyes');"  /> 
                                <img src="static/images/emo/sad.gif" alt="sad" onclick="addEmoticon('topic_content', 'sad');"  /> 
                                <img src="static/images/emo/scared.gif" alt="scared" onclick="addEmoticon('topic_content', 'scared');"  /> 
                                <img src="static/images/emo/sleep.gif" alt="sleep" onclick="addEmoticon('topic_content', 'sleep');"  /> 
                                <img src="static/images/emo/smile.gif" alt="smile" onclick="addEmoticon('topic_content', 'smile');"  /> 
                                <img src="static/images/emo/sneaky.gif" alt="sneaky" onclick="addEmoticon('topic_content', 'sneaky');"  /> 
                                <img src="static/images/emo/thumbdn.gif" alt="thumbdn" onclick="addEmoticon('topic_content', 'thumbdn');"  /> 
                                <img src="static/images/emo/thumbsup.gif" alt="thumbsup" onclick="addEmoticon('topic_content', 'thumbsup');"  /> 
                                <img src="static/images/emo/thumbup.gif" alt="thumbup" onclick="addEmoticon('topic_content', 'thumbup');"  /> 
                                <img src="static/images/emo/tongue.gif" alt="tongue" onclick="addEmoticon('topic_content', 'tongue');"  /> 
                                <img src="static/images/emo/unsure.gif" alt="unsure" onclick="addEmoticon('topic_content', 'unsure');"  /> 
                                <img src="static/images/emo/w00t.gif" alt="w00t" onclick="addEmoticon('topic_content', 'w00t');"  /> 
                                <img src="static/images/emo/wink.gif" alt="wink" onclick="addEmoticon('topic_content', 'wink');"  /> 

                            </td>
                            
                            <td>
                                {$input_hidden_forumid}
                            </td>
                        </tr>
                        <tr>
                            <td>

                            </td>

                        </tr>


                    </table>
                    {$closeTopicForm}

                {else}
                    <!-- Sezione per i Forums -->
                    <tr>
                        <td class="tb_head" style="padding-left: 15px;" colspan="2">{$forum->name}</td>
                        <td class="tb_head" align="center">Statistiche</td>
                        <td class="tb_head" align="center">Ultimo mess.</td>
                    </tr>
                    {foreach from=$forum->getTopics() item=topic name=topics}
                        <tr class="li">
                            <td class="ic" width="40">
                                <a href="forum.php5?mode=topic&id=1">
                                    {if $topic->status == 0}
                                        <img border="0" alt="" src="static/images/layout/lockclosetopic.png">
                                    {else}
                                        <img border="0" alt="" src="static/images/layout/emptyfolder.png">
                                    {/if}
                                </a>
                            </td>
                            <td class="c1" width="315">
                                <a href="forum.php?mode=topic&id={$topic->id_topic}">{$topic->name}</a>
                                <div class="dat" align="right">
                                    creata da 
                                    <a id="m" class="a_profilo" href="profilo.php5?id=11402">{$topic->creator}</a>
                                </div>
                            </td>
                            <td class="c2" width="100">
                                <div class="dat">
                                    {$topic->getNrPosts()} mess.
                                    <br>
                                    {$topic->views} visite
                                </div>
                            </td>
                            <td class="c3" width="120">
                                <div class="dat">
                                    {if $forum->getLastMessageDate() neq false}
                                        {Util::getDate($forum->getLastMessageDate())} alle {Util::getTime($forum->getLastMessageDate())}
                                    {/if}
                                    <br />
                                    {if $forum->getLastMessageCreator() neq "nessuno"}
                                    da 
                                    <a id="m" class="a_profilo" href="profile.php?username={$forum->getLastMessageCreator()}">{$forum->getLastMessageCreator()}</a>
                                   
                                    {else}
                                        Nessun messaggio
                                    {/if}
                                    
                                </div>
                            </td>
                        </tr>
                    {/foreach}
                {/if}
            {elseif isset($mode) && $mode eq 'topic'}
                <!-- Sezione per i POST -->
                <br /> <br />
                <h3><img style="vertical-align:middle; padding-right: 20px;"src="static/images/layout/topiclogo.png" /><font style="text-decoration: underline; color:#3521AB;">Discussione:</font> {$topic->name}</h3>
                <table class="tab" width="590" bordercolor="#5C5C5C" border="1">
                    <tbody>
                        <!-- primo messaggio -->
                        {if $start eq 0}
                            <tr>
                                <td class="tb_head" width="100" style="padding-left: 15px;">Mittente</td>
                                <td class="tb_head" width="490" align="center">Messaggio</td>
                            </tr>
                            <tr class="li">
                                <td class="p1">
                                    <div align="right">
                                        {if $user->isOnlineUser($topic->creator, true)}
                                            <img style="vertical-align: middle;" border="0" alt="" src="static/images/layout/online.png" />
                                        {else}
                                            <img style="vertical-align: middle;" border="0" alt="" src="static/images/layout/offline.png" />

                                        {/if}
                                        
                                        <a id="m" class="a_profilo" href="profile.php?username={$topic->creator}">{$topic->creator}</a>
                                        <br>
                                        <a href="profile.php?username={$topic->creator}">
                                            <img class="img1" border="0" alt="" src="{User::getCreatorImage($topic->creator)}">
                                        </a>
                                        {if $user->username eq $topic->creator}
                                            {if $topic->status eq 1}
                                                <a href="forum.php?mode=topic&id={$topic->id_topic}&action=close">
                                                    <img border="0" alt="" src="static/images/layout/lockclosetopic.png" />
                                                </a>
                                            {/if}
                                            {if $topic->status eq 0}
                                                <a href="forum.php?mode=topic&id={$topic->id_topic}&action=open">
                                                    <img border="0" alt="" src="static/images/layout/lockopentopic.png" />
                                                </a>
                                            {/if}
                                            
                                            
                                        {/if}
                                        {if $user->isAdmin()}
                                            <a href="forum.php?mode=topic&id={$topic->id_topic}&action=delete">
                                                <img border="0" alt="" src="static/images/layout/deletetopic.png" />
                                            </a>
                                        {/if}
                                    </div>
                                </td>
                                <td class="p1" valign="top">
                                    <table width="100%" cellspacing="0" cellpadding="0">
                                        <tbody>
                                            <tr>
                                                <td class="small" valign="top">
                                                    <a name="p2571780"></a>
                                                    <img border="0" alt="" src="static/images/layout/sent.png">
                                                    <b>Inviato:</b>
                                                    {Util::getDate($topic->creation_date)} alle {Util::getTime($topic->creation_date)}
                                                </td>
                                                <td class="small" valign="top" align="right"> </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                    <hr width="100%" size="1" noshade="" color="#5C5C5C" align="left">
                                    <div class="mess_int">
                                        {Util::parsePostContent($topic->content)}
                                    </div>
                                </td>
                            </tr>
                        {/if}
                        {foreach from=$topic->getPosts($start, $post_page) item=post name=posts}

                            <tr class="li">
                                <td class="p2">
                                    <div align="right">
                                        {if $user->isOnlineUser($post->creator, true)}
                                            <img style="vertical-align: middle;" border="0" alt="" src="static/images/layout/online.png" />
                                        {else}
                                            <img style="vertical-align: middle;" border="0" alt="" src="static/images/layout/offline.png" />

                                        {/if}
                                        <a id="m" class="a_profilo" href="profile.php?username={$post->creator}">{$post->creator}</a>
                                        <br>
                                        <a href="profile.php?username={$post->creator}">
                                            <img class="img1" border="0" alt="" src="{User::getCreatorImage($post->creator)}" />
                                        </a>
                                    </div>
                                </td>
                                <td class="p2" valign="top">
                                    <table width="100%" cellspacing="0" cellpadding="0">
                                        <tbody>
                                            <tr>
                                                <td class="small" valign="top">
                                                    <a name="p2571787"></a>
                                                    <img border="0" alt="" src="static/images/layout/sent.png">
                                                    <b>Inviato:</b>
                                                    {Util::getDate($post->creation_date)} alle {Util::getTime($post->creation_date)}

                                                </td>
                                                <td class="small" valign="top" align="right"> {if $post->creator eq $user->username}<a href="forum.php?mode=de&id={$post->id_post}">Cancella</a>{/if} <a href="#footer" onclick="quoteMessage('{$post->creator}', '{$post->content}');">Rispondi</a></td>
                                            </tr>
                                        </tbody>
                                    </table>
                                    <hr width="100%" size="1" noshade="" color="#5C5C5C" align="left">
                                    <div class="mess_int">
                                        {Util::parsePostContent($post->content)}
                                    </div>
                                </td>
                            </tr>

                        {/foreach}

                    </tbody>
                </table>
                <div style="text-align: right;padding-right: 20px;">
                    <!-- PAGINAZIONE -->
                    {if (isset($start) && $start neq 0)}
                        <a href="forum.php?mode={$mode}&id={$id_topic}&start={$start-$post_page}">Precedente</a>
                    {/if}
                    {for $i=1 to ($topic->getNrPosts()/$post_page)}
                    {if !isset($start) && $i eq 1}
                        {$i}, 
                    {elseif isset($start) && $i eq $start/$post_page+1}
                    {$i}{if $i neq intval($topic->getNrPosts()/$post_page+1)},{/if}
                {else}
                    <a href="forum.php?mode={$mode}&id={$id_topic}&start={($i*$post_page)-$post_page}">{$i}</a>{if $i neq intval($topic->getNrPosts()/$post_page+1)},{/if}
                {/if}
                {/for}
                {if !isset($start)}
                    <a href="forum.php?mode={$mode}&id={$id_topic}&start={$post_page}">Prossima</a>
                {else}
                    {if !isset($start) || (isset($start) && $start/$post_page neq intval($topic->getNrPosts()/$post_page))}

                        <a href="forum.php?mode={$mode}&id={$id_topic}&start={$start+$post_page}">Prossima</a>
                    {/if}

                {/if}
            </div>
            {if isset($topic) && $topic->status neq 0}
            <!-- Formulario per mandare un POST -->
            <h3>Rispondi</h3>
            {$openPostForm}
            <table id="reply_message">
                <tr>
                    <td>
                        {$textarea_post}
                    </td>
                </tr>
                <tr>
                    <td>
                        {$submit_post} 
                    </td>
                    <td>
                        {$input_hidden_topicid}
                    </td>
                    <td>
                        {$input_hidden_topicstatus}
                    </td>
                </tr>
                <tr>
                    <td>
                        <h3>Smiles</h3>
                        
                        <img src="static/images/emo/angry.gif" alt="angry" onclick="addEmoticon('post_text', 'angry');" /> 
                        <img src="static/images/emo/biggrin.gif" alt="biggrin" onclick="addEmoticon('post_text', 'biggrin');"  /> 
                        <img src="static/images/emo/blink.gif" alt="blink" onclick="addEmoticon('post_text', 'blink');"  /> 
                        <img src="static/images/emo/blushing.gif" alt="blushing" onclick="addEmoticon('post_text', 'blushing');"  /> 
                        <img src="static/images/emo/bored.gif" alt="bored" onclick="addEmoticon('post_text', 'bored');"  />
                        <img src="static/images/emo/confused.gif" alt="confused" onclick="addEmoticon('post_text', 'confused');"  /> 
                        <img src="static/images/emo/cool.gif" alt="cool" onclick="addEmoticon('post_text', 'cool');"  /> 
                        <img src="static/images/emo/crying.gif" alt="crying" onclick="addEmoticon('post_text', 'crying');"  /> 
                        <img src="static/images/emo/cursing.gif" alt="cursing" onclick="addEmoticon('post_text', 'cursing');"  /> 
                        <img src="static/images/emo/drool.gif" alt="drool" onclick="addEmoticon('post_text', 'drool');"  /> 
                        <img src="static/images/emo/flapper.gif" alt="flapper" onclick="addEmoticon('post_text', 'flapper');"  /> 
                        <img src="static/images/emo/glare.gif" alt="glare" onclick="addEmoticon('post_text', 'glare');"  /> 
                        <img src="static/images/emo/huh.gif" alt="huh" onclick="addEmoticon('post_text', 'huh');"  /> 
                        <img src="static/images/emo/laugh.gif" alt="laugh" onclick="addEmoticon('post_text', 'laugh');"  /> 
                        <img src="static/images/emo/lol.gif" alt="lol" onclick="addEmoticon('post_text', 'lol');"  /> 
                        <img src="static/images/emo/love.gif" alt="love" onclick="addEmoticon('post_text', 'love');"  /> 
                        <img src="static/images/emo/mad.gif" alt="mad" onclick="addEmoticon('post_text', 'mad');"  /> <br />
                        <img src="static/images/emo/mellow.gif" alt="mellow" onclick="addEmoticon('post_text', 'mellow');"  /> 
                        <img src="static/images/emo/ohmy.gif" alt="ohmy" onclick="addEmoticon('post_text', 'ohmy');"  /> 
                        <img src="static/images/emo/rolleyes.gif" alt="rolleyes" onclick="addEmoticon('post_text', 'rolleyes');"  /> 
                        <img src="static/images/emo/sad.gif" alt="sad" onclick="addEmoticon('post_text', 'sad');"  /> 
                        <img src="static/images/emo/scared.gif" alt="scared" onclick="addEmoticon('post_text', 'scared');"  /> 
                        <img src="static/images/emo/sleep.gif" alt="sleep" onclick="addEmoticon('post_text', 'sleep');"  /> 
                        <img src="static/images/emo/smile.gif" alt="smile" onclick="addEmoticon('post_text', 'smile');"  /> 
                        <img src="static/images/emo/sneaky.gif" alt="sneaky" onclick="addEmoticon('post_text', 'sneaky');"  /> 
                        <img src="static/images/emo/thumbdn.gif" alt="thumbdn" onclick="addEmoticon('post_text', 'thumbdn');"  /> 
                        <img src="static/images/emo/thumbsup.gif" alt="thumbsup" onclick="addEmoticon('post_text', 'thumbsup');"  /> 
                        <img src="static/images/emo/thumbup.gif" alt="thumbup" onclick="addEmoticon('post_text', 'thumbup');"  /> 
                        <img src="static/images/emo/tongue.gif" alt="tongue" onclick="addEmoticon('post_text', 'tongue');"  /> 
                        <img src="static/images/emo/unsure.gif" alt="unsure" onclick="addEmoticon('post_text', 'unsure');"  /> 
                        <img src="static/images/emo/w00t.gif" alt="w00t" onclick="addEmoticon('post_text', 'w00t');"  /> 
                        <img src="static/images/emo/wink.gif" alt="wink" onclick="addEmoticon('post_text', 'wink');"  /> 
                    </td>

                </tr>
                {if !$topic->isFavorite($user->username)}
                <tr>
                    
                    <td>
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    
                    <td>
                        <img src="static/images/layout/favorite.png" /> <a href="forum.php?mode=addfav&id={$topic->id_topic}">Aggiungi ai preferiti</a>
                    </td>
                </tr>
                {else}
                    <tr>
                    
                    <td>
                        &nbsp;
                    </td>
                    </tr>
                    <tr>

                        <td>
                            <img src="static/images/layout/favorite.png" /> <a href="forum.php?mode=rmfav&id={$topic->id_topic}">Rimuovi dai preferiti</a>
                        </td>
                    </tr>
                {/if}
                
            </table>
            {$closePostForm}
            {/if}
        {/if}
        

        </tbody>
    </table>

    {else}
        {include file="{$TEMPLATES_URL}login_form.tpl"}
{/if}
</div>
</div>

</div>
